<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start();
//error_reporting(E_ALL);
/**
 *
 * @author ANDRINIRINA Aimé Jules
 * @tel 261 34 60 011 66
 * @email aimejules1@gmail.com
 */

class Listclinic extends CI_Controller {

	private $per_page = 5;
	private $uri_segment = 3;
	
	function __construct()
	    {
		parent::__construct();
		$this->load->helper('url');
		$this->load->helper(array('form', 'url'));
		$this->load->library('form_validation');
		$this->load->library('session');
                $this->load->library('uri');
                $this->load->model('mod_pays');
                $this->load->model('mod_ville');
                $this->load->model('mod_clinic');
                $this->load->model('mod_listclinic');
                $this->load->library('lang');
	    }

        function index (){
                $lg = $this->uri->segment(1,0);
                $_SESSION['lg']=$lg;
                $this->lang->load('header',$lg);
                $this->lang->load('lien',$lg);
                $this->lang->load('container',$lg);
                $this->lang->load('footer',$lg);
                $this->load->library("pagination");
                $config = array();
                $config["base_url"] = base_url() .$_SESSION['lg']."/".$this->lang->line('lien_clinic')."/";
                $config["total_rows"] = $this->mod_listclinic->record_count_getAllClinicFetch();
                $config["per_page"] = 6;
                $config["uri_segment"] = $this->uri_segment;
                $this->pagination->initialize($config);
                $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
                $data['result']=$this->mod_listclinic->getAllClinicFetch($config["per_page"], $page);
                $data["links"] = $this->pagination->create_links();
                $this->load->view('clinic/vue_listclinic',$data);
        }
        
        function search (){
            
            $pays = $this->input->post('pays');
            $ville = $this->input->post('ville');
            $keywords = $this->input->post('keywords');
            $language = $this->input->post('language');
            
            echo " pays: $pays, ville:$ville, keywords:$keywords, language:$language ";
            
            if (isset($_POST['submit']))
            {
                echo "hhhhhhhhh";
                $lg = $this->uri->segment(1,0);
                $_SESSION['lg']=$lg;
                $this->lang->load('header',$lg);
                $this->lang->load('lien',$lg);
                $this->lang->load('container',$lg);
                $this->lang->load('footer',$lg);
                $this->load->library("pagination");
                $config = array();
                $config["base_url"] = base_url() .$_SESSION['lg']."/".$this->lang->line('lien_clinic')."/";
                $config["total_rows"] = $this->mod_listclinic->record_count_getClinicFetch($pays,$ville,$keywords,$language);
                $config["per_page"] = 6;
                $config["uri_segment"] = $this->uri_segment;
                $this->pagination->initialize($config);
                $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
                $data['result']=$this->mod_listclinic->getClinicFetch($pays,$ville,$keywords,$language,$config["per_page"], $page);
                $data["links"] = $this->pagination->create_links();
                $this->load->view('clinic/vue_listclinic',$data);
            } else {
                
                echo "nnnnnn";
               
                $this->load->view('clinic/vue_listclinic',$data);
            }     
        }
        
        /*afficher liste clinique par pays*/
        function pays(){
                $lg = $this->uri->segment(1,0);
                $donne_clinique ['pays'] = $this->uri->segment(3,0);
                $id_pays =$this->mod_listclinic->getIdPaysByName($donne_clinique ['pays']);
                $_SESSION['lg']=$lg;
                $this->lang->load('header',$lg);
                $this->lang->load('lien',$lg);
                $this->lang->load('container',$lg);
                $this->lang->load('footer',$lg);
                $this->load->library("pagination");
                $config = array();
                $config["base_url"] = base_url() .$_SESSION['lg']."/".$this->lang->line('lien_clinic')."/";
                $config["total_rows"] = $this->mod_listclinic->getNbClinicByPays($id_pays);
                $config["per_page"] = 6;
                $config["uri_segment"] = $this->uri_segment;
                $this->pagination->initialize($config);
                $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
                $data['result']=$this->mod_listclinic->getAllClinicByPays($id_pays,$config["per_page"], $page);
                $data["links"] = $this->pagination->create_links();
                $this->load->view('clinic/vue_listclinic_pays',$data);
            
        }
        /*afficher liste clinique par ville*/
        function ville(){
            $lg = $this->uri->segment(1,0);
                $donne_clinique ['pays'] = $this->uri->segment(3,0);
                $donne_clinique['ville'] = $this->uri->segment(4,0);
                $id_ville =$this->mod_listclinic->getIdVilleByName($donne_clinique ['ville']);
                $_SESSION['lg']=$lg;
                $this->lang->load('header',$lg);
                $this->lang->load('lien',$lg);
                $this->lang->load('container',$lg);
                $this->lang->load('footer',$lg);
                $this->load->library("pagination");
                $config = array();
                $config["base_url"] = base_url() .$_SESSION['lg']."/".$this->lang->line('lien_clinic')."/";
                $config["total_rows"] = $this->mod_listclinic->getNbClinicByVille($id_ville);
                $config["per_page"] = 6;
                $config["uri_segment"] = $this->uri_segment;
                $this->pagination->initialize($config);
                $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
                $data['result']=$this->mod_listclinic->getAllClinicByVille($id_ville,$config["per_page"], $page);
                $data["links"] = $this->pagination->create_links();
                $this->load->view('clinic/vue_listclinic_ville',$data);
        }
}
?>